<?php

namespace App\Jobs;

use App\Models\User;
use App\Models\GoldRecord;
use Brick\Math\RoundingMode;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Redis;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Events\GoldRecordPaidEvent;
use Rainsens\Dinglog\Facades\Dinglog;
use Carbon\Carbon;
use App\Services\ApplyGoldRecordBatchExamine\ApplyGoldRecordBatchExamine;

class ExamineGoldProductPayingJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected User $user;
    protected string $unpaidCacheId;
    protected string $examineCacheId;

    public function __construct(User $user, $unpaidCacheId,$examineCacheId)
    {
        $this->user = $user;
        $this->unpaidCacheId = $unpaidCacheId;
        $this->examineCacheId = $examineCacheId;
        $this->delay(Carbon::now()->addMinutes(sc('examine_expire_minuts')));
    }

    public function handle()
    {
        
        $isContact = Redis::hGet($this->unpaidCacheId,'is_contact');
        $isExamine = Redis::hGet($this->unpaidCacheId,'is_examine');
        if($isContact) return;
        if($isExamine) return;
        Dinglog::text($this->examineCacheId);
        Dinglog::text($this->unpaidCacheId);
        
        app(ApplyGoldRecordBatchExamine::class, [
            'user' => $this->user,
            'unpaidCacheIds' => [$this->unpaidCacheId],
            'examineRecord' => $this->examineCacheId,
        ])->examine();
    }
}
